package com.company;
import java.io.IOException;
import java.io.InputStream;

public class MyRequest {
    private String url;
    private String method;

    public MyRequest(InputStream inputStream) throws IOException{
        String httpRequest="";
        byte[] httpRequestBytes=new byte[1024];
        int length=0;
        if( (length=inputStream.read(httpRequestBytes))>0 ){
            httpRequest=new String(httpRequestBytes,0,length);
        }

        //对http协议进行解析
        //拿到http请求头的方法和URL
        String httpHead=httpRequest.split("\n")[0];
        url=httpHead.split("\\s")[1];
        method=httpHead.split("\\s")[0];

        System.out.println(method);
        System.out.println(url);
    }

    public String getUrl() {
        return url;
    }

    public String getMethod() {
        return method;
    }
}
